package com.example.springtime.controller;

import com.example.springtime.entity.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class ThymleafController {
    @Autowired
    protected JdbcTemplate secondaryJdbcTemplate;
    @GetMapping("index")
    public String getindex(Model model) {
            List<Book> books1 = secondaryJdbcTemplate.query("select * from book",
                    new BeanPropertyRowMapper<>(Book.class));
            model.addAttribute("bookList",books1);
            return "index";
        }
}
